package com.ikaros.concurrency.example.collections;

import lombok.extern.slf4j.Slf4j;

import java.util.*;

@Slf4j
public class ListAndVector {
    private static List<Integer> list = new ArrayList<Integer>();

    private static Vector<Integer> vector = new Vector<Integer>();

    private static void iteratorList() {
        //list.remove(i);
        list.removeIf(i -> i.equals(3));
        Iterator<Integer> iterator = list.iterator();
        while (iterator.hasNext()) {
            Integer i = iterator.next();
            if (i.equals(3)) {
                //list.remove(i);  //这样remove会报错  代表当前list的值
                iterator.remove();
            }
        }
        log.info("list-{}",list.toString());
    }

    private static void iteratorVector() {
        //list.remove(i);
        //vector.removeIf(i -> i.equals(3));
        Iterator<Integer> iterator = vector.iterator();
        while (iterator.hasNext()) {
            Integer i = iterator.next();
            if (i.equals(3)) {
                iterator.remove();
            }
        }
        log.info("vector-{}",list.toString());
    }

    public static void main(String[] args) {
        list.add(1);
        list.add(2);
        list.add(3);
        iteratorList();
        vector.add(3);
        vector.add(2);
        vector.add(3);
        iteratorVector();
    }
}
